﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenExpressApp.MetaAttribute;
using Csla.Wpf;
using OpenExpressApp.Command;
using Csla.Core;
using System.ComponentModel;
using System.Windows;
using OpenExpressApp.Template;
using OpenExpressApp.Types;
using Csla;
using OpenExpressApp.WPF.Controls;
using System.Collections.ObjectModel;
using log4net;
using System.Collections;
using OpenExpressApp.MetaModel;
using Avalon.Windows.Controls;
using OpenExpressApp.WPF.Templete;
using OpenExpressApp.Module;
using OpenExpressApp.Module.WPF;
using System.Windows.Controls;
using Ricciolo.Controls;
using System.Reflection;
using System.Windows.Markup;
using System.Diagnostics;
using AvalonDock;
using OpenExpressApp.Module.WPF.Editors;
using Csla.OpenExpressApp;

namespace OpenExpressApp.WPF.Command
{
    /// <summary>
    /// View为NavigateQueryObjectView
    /// </summary>
    [Command(CommandNames.QueryObject, Label = "查询", ToolbarType = ToolbarType.Manual, ToolTip = "查询记录")]
    public class QueryObjectCommand : WPFViewCommand
    {
        public override void Execute(ObjectView view)
        {
            Debug.Assert(view is QueryObjectView, "此命令只能在导航查询面板视图QueryObjectView中使用");

            var queryObject = view.CurrentObject as IQueryObject;
            queryObject.CheckRules();
            if (queryObject.BrokenRulesCollection.Count > 0)
            {
                TaskDialog.Show(queryObject.BrokenRulesCollection[0].Description, "条件错误");
            }
            else
            {
                var resultView = (view as QueryObjectView).ResultView;
                this.QueryData(resultView, queryObject);
            }
        }

        protected virtual void QueryData(ObjectView resultView, IQueryObject queryObject)
        {
            resultView.DataLoader.AsyncGetObject(queryObject);
        }
    }
}
